﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/06/16
 * 
 * 功能说明：数据字典选项值管理页面
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Config_Choice : System.Web.UI.Page
{
    protected string action = "";
    protected int TypeID = 0;
    protected int ChoiceID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        action = NetRequest.GetQueryString("Action");
        TypeID = NetRequest.GetQueryInt("TypeID");
        ChoiceID = NetRequest.GetQueryInt("ChoiceID");

        ltTitle.Text = new Whir.BLL.Whir_ChoiceType().GetModel(TypeID).choiceTypeMark;
        if (!IsPostBack)
        {
            switch (action)
            {
                case "Add": break;
                case "Modify":
                    BindData();
                    btnSumbit.Text = "更新";
                    break;
                case "Delete":
                    BindData();
                    btnSumbit.Text = "删除";
                    btnSumbit.Attributes.Add("onclick", "return confirm('确定要删除吗？');");
                    break;
            }
        }
    }

    private void BindData()
    {
        Whir.BLL.Whir_Choice bll = new Whir.BLL.Whir_Choice();
        Whir.Model.Whir_Choice model = bll.GetModel(ChoiceID);
        txtChoiceText.Text = model.choiceText;
        radIsDefaultValue.SelectedValue = model.IsDafaultValue.ToString();
        radIsUse.SelectedValue = model.IsUse.ToString();
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_Choice bll = new Whir.BLL.Whir_Choice();
        Whir.Model.Whir_Choice model;
        switch (action)
        {
            case "Add":
                model = new Whir.Model.Whir_Choice();
                model.choiceTypeID = TypeID;
                model.choiceText = txtChoiceText.Text.Trim();
                model.IsDafaultValue = Convert.ToBoolean(radIsDefaultValue.SelectedValue);
                model.IsUse = Convert.ToBoolean(radIsUse.SelectedValue);
                bll.Add(model);
                break;
            case "Modify":
                model = bll.GetModel(ChoiceID);
                model.choiceTypeID = TypeID;
                model.choiceText = txtChoiceText.Text.Trim();
                model.IsDafaultValue = Convert.ToBoolean(radIsDefaultValue.SelectedValue);
                model.IsUse = Convert.ToBoolean(radIsUse.SelectedValue);
                bll.Update(model);
                break;
            case "Delete":
                model = bll.GetModel(ChoiceID);
                if (model != null)
                {
                    bll.Delete(ChoiceID);
                }
                break;
        }

        Response.Redirect("ChoiceManage.aspx?TypeID=" + TypeID);
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ChoiceManage.aspx?TypeID=" + TypeID);
    }
}
